package interface_layer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import date_layer.Coordinator;

public class panel_client extends JPanel implements ActionListener
{
	private Coordinator coordinator;
	private JLabel Image;
	private JLabel Information;
	private JLabel Name;
	private JLabel _id;
	private JTextField id;
	private JButton botonSearch;
	private JButton botonSave;
	private JTextField name;
	private JScrollPane scroll_area;
	private JTextArea show_result_area;

	public panel_client(Coordinator coordinator) 
	{
		this.coordinator = coordinator;
		initComponents();
	}

	private void initComponents()
	{
		name = new JTextField();
		id = new JTextField();
		botonSearch = new JButton();
		botonSave = new JButton();
		scroll_area = new JScrollPane();
		show_result_area = new JTextArea();
		Name = new JLabel();
		Information = new JLabel();
		_id = new JLabel();
		Image = new JLabel();

		setPreferredSize(new java.awt.Dimension(600, 380));
		setLayout(null);

		add(name);
		name.setBounds(20, 160, 190, 20);
		add(id);
		id.setBounds(20, 230, 190, 20);

		botonSearch.setText("Search");
		botonSearch.addActionListener(this);
		add(botonSearch);
		botonSearch.setBounds(20, 340, 75, 23);

		botonSave.setText("Save");
		botonSave.addActionListener(this);
		add(botonSave);
		botonSave.setBounds(140, 340, 70, 23);

		show_result_area.setColumns(20);
		show_result_area.setRows(5);
		scroll_area.setViewportView(show_result_area);

		add(scroll_area);
		scroll_area.setBounds(280, 20, 290, 320);

		Name.setText("Name");
		add(Name);
		Name.setBounds(20, 140, 90, 14);

		Information.setText("Information");
		add(Information);
		Information.setBounds(280, 350, 200, 14);

		_id.setText("Id");
		add(_id);
		_id.setBounds(20, 210, 110, 14);
		add(Image);
		Image.setBounds(20, 20, 250, 90);
		Image.setIcon(new ImageIcon("src\\images\\cliente.png"));
	}

	
	public void actionPerformed(ActionEvent e)
	{
		if ( e.getSource() == botonSave)
		{
			if (name.getText().equals("") || id.getText().equals("") )
			{
				Information.setText("debe llenar todos los campos");
			}
			else
			{
				coordinator.manageClient(1, name.getText(), id.getText());
			}
		}
		else
		{
			if ( e.getSource() == botonSearch)
			{
				if (name.getText().equals("") && id.getText().equals("") )
				{
					Information.setText("debe llenar algun campo");
				}
				else
				{
					coordinator.manageClient(2, name.getText(), id.getText());
				}
			}
		}
	}
}
